<?php
class Admin_Model_Project extends Admin_Model_Base {

    protected $sqls = array(
        'get_list'  => 'select * from `fi_project` {{@where}} order by {{@order_by}} limit {{@limit}};',
        'get_all_count_validity_date' => 'select count(1) from `fi_project` where `project_validity_date`>[@now];',
    );
    
    public function __construct(){
        parent::__construct();
    }

    public $_project_category = array(
        'p10'  => array(
            'title' => '项目融资',
            'info'  => '从广义上讲，为了建设一个新项目或者收购一个现有项目，或者对已有项目进行债务重组所进行的一切融资活动的信息。 从狭义上讲，是指以项目的资产、预期收益或权益作抵押或置换取得的一种融资或贷款活动。比如：创业项目，技改项目等等。',
            'sub'   => array(
                's110' => array(
                    'title' => '整体转让',
                    'info'  => '希望进行整体出让'
                ), 
                's120' => array(
                    'title' => '股权融资',
                    'info'  => '希望以渡让部分项目权益的方式获得融资'
                ),
                's130' => array(
                    'title' => '债券融资',
                    'info'  => '希望以项目为标的获得债权性融资'
                ),
                's140' => array(
                    'title' => '项目合作',
                    'info'  => '希望寻找与项目相关的上下游合作机构，进行多种类型合作的需求'
                ),
            ),
            'has_url'   => 0
        ),
        'p20'  => array(
            'title' => '资产交易',
            'info'  => '发布方持有有明确的标的物，发布方有将其资产所有权和经营权全部或者部分有偿转让的需求。这种经济活动一般是以实物形态为基本特征的出卖财产收益的行为，当然也可以是交易无形资产。比如：车，不动产，设备，商铺等等。',
            'sub'   => array(
                's210' => array(
                    'title' => '股权',
                    'info'  => ''
                ), 
                's215' => array(
                    'title' => '矿权',
                    'info'  => '包括勘探权，开采权等'
                ),
                's220' => array(
                    'title' => '房产',
                    'info'  => '主要指商业地产'
                ),
                's225' => array(
                    'title' => '土地',
                    'info'  => ''
                ),
                's230' => array(
                    'title' => '债权及账款',
                    'info'  => ''
                ),
                's235' => array(
                    'title' => '林权',
                    'info'  => ''
                ),
                's240' => array(
                    'title' => '设备及器械',
                    'info'  => '大宗设备与机械'
                ),
                's245' => array(
                    'title' => '车产',
                    'info'  => ''
                ),
                's250' => array(
                    'title' => '证券',
                    'info'  => '场外市场的证券交易信息'
                ),
                's255' => array(
                    'title' => '商标',
                    'info'  => ''
                ),
                's260' => array(
                    'title' => '专利',
                    'info'  => ''
                ),
                's265' => array(
                    'title' => '域名',
                    'info'  => ''
                ),
                's270' => array(
                    'title' => '其他',
                    'info'  => ''
                ),
            ),
            'has_url'   => 0
        ),
        'p30'  => array(
            'title' => '投资理财',
            'info'  => '发布方有金融化，标准化的理财产品希望推荐，欲寻求合适的认购者的信息，比如信托，私募基金等等。',
            'sub'   => array(
                's310' => array(
                    'title' => '信托',
                    'info'  => '信托产品信息'
                ), 
                's320' => array(
                    'title' => '银行',
                    'info'  => '银行大额理财产品'
                ),
                's330' => array(
                    'title' => '私募',
                    'info'  => '私募项目信息'
                ),
                's340' => array(
                    'title' => '其他',
                    'info'  => '其他由各类金融机构产出的理财产品'
                ),
            ),
            'has_url'   => 0
        ),
        'p40'  => array(
            'title' => '其他融资',
            'info'  => '其他各种形式的项目方对资金或资本的需求信息比如：保证保函，投标融资等等。',
            'has_url'   => 1
        ),
        'p50'  => array(
            'title' => '政府招商',
            'info'  => '由地方政府或相关部门发布的招商信息',
            'has_url'   => 1
        )
    );

    public $_project_stage = array(
        0 => '不限',
        1 => '种子期',
        2 => '初创期',
        3 => '成长期',
        4 => '扩张期',
        5 => '成熟期',
        6 => 'Pre-IPO',
    );

    public $_project_mode = array(
        0 => '不限',
        1 => '债权类',
        2 => '股权类',
        3 => '其他',
    );

    public $_project_pledge = array(
        1 => '固定资产',
        2 => '有价证券',
        3 => '流动资产',
        4 => '无形资产',
        5 => '其他',
    );

    public $_project_financing_status = array(
        0 => '否',
        1 => '是',
    );

    public $_project_transfer_form = array(
        1 => '整体',
        2 => '部分',
    );

    public $_project_transaction_mode = array(
        1 => '拍卖',
        2 => '竞价',
        3 => '招标',
        4 => '协议',
    );

    public $_project_house_type = array(
        0 => '不限',
        1 => '住宅',
        2 => '商铺',
        3 => '写字楼',
        4 => '厂房',
        5 => '仓库',
        6 => '车位',
        7 => '其他',
    );

    public $_project_debt_value = array(
        0 => '抵押',
        1 => '出售',
        2 => '其他',
    );

    public $_project_affiance_company = array(
        1 => '中信信托',
        2 => '平安信托',
        3 => '中融信托',
        4 => '粤财信托',
        5 => '山东信托',
        6 => '华宝信托',
        7 => '外贸信托',
        8 => '北京信托',
        9 => '渤海信托',
        10 => '建信信托',
        11 => '华润信托',
        12 => '新华信托',
        13 => '上海信托',
        14 => '华融信托',
        15 => '北方信托',
        16 => '吉林信托',
        17 => '中铁信托',
        18 => '华能信托',
        19 => '华信信托',
        20 => '重庆信托',
        21 => '国元信托',
        22 => '交银国际信托',
        23 => '中原信托',
        24 => '天津信托',
        25 => '新时代信托',
        26 => '百瑞信托',
        27 => '江苏信托',
        28 => '山西信托',
        29 => '陕西国投',
        30 => '中投信托',
        31 => '厦门信托',
        32 => '湖南信托',
        33 => '中泰信托',
        34 => '苏州信托',
        35 => '东莞信托',
        36 => '华宸信托',
        37 => '安信信托',
        38 => '金谷信托',
        39 => '杭州信托',
        40 => '五矿信托',
        41 => '爱建信托',
        42 => '甘肃信托',
        43 => '华澳信托',
        44 => '云南信托',
        45 => '国民信托',
        46 => '国投信托',
        47 => '其他',
    );

    public $_project_affiance_bearing = array(
        0 => '不限',
        1 => '矿产',
        2 => '金融证券',
        3 => '房地产',
        4 => '工商企业',
        5 => '艺术品收藏',
        6 => '基础设施建设',
        7 => '其它',
    );

    public $_project_affiance_class = array(
        0 => '不限',
        1 => '组合投资',
        2 => '贷款信托',
        3 => '股权投资信托',
        4 => '权益投资信托',
        5 => '债权投资信托',
        6 => '证券投资信托',
        7 => '融资租赁信托',
        8 => '其它',
    );

    public $_project_private_place = array(
        1 => '交易所',
        2 => '银行间市场',
        3 => '民间市场',
    );

    public function get_list($condition = array(), $page = 1, $page_size = 10, $order_by = 'updated desc'){
        $page_index = ($page>=1)?($page-1)*$page_size:0;
        $whereArr = array();
        if(empty($condition))
            $sql = str_replace('{{@where}}',' WHERE `project_validity_date`>'.time(),$this->sqls['get_list']);
        else{
            $condition['project_validity_date'] = array('symbol'=>'>','value'=>time());
            $whereStr = $this->_where($condition, $whereArr);
            $sql = str_replace('{{@where}}',$whereStr,$this->sqls['get_list']);
        }

        $sql = str_replace('{{@order_by}}',$order_by,$sql);
        $sql = str_replace('{{@limit}}',$page_index.','.$page_size,$sql);
        return mysql::fetch('project', $sql, $whereArr);
    }

    //获取所有记录数
    public function get_all_count_validity_date(){
        $now = time();
        $c = mysql::fetch('project', $this->sqls['get_all_count_validity_date'],array('now'=>$now));
        return $c[0]['count(1)'];
    }
}